<?php

    /**
    * API Controller.
    *
    * Helpful methods to make Controller.
    *
    * PHP versions 5
    * CAKEPHP versions 2.x
    * 
    * Green CMS - Content Management System and Framework Powerfull by Cakephp
    * Copyright 2014, GREEN GLOBAL CO., LTD (toancauxanh.vn)
    * 
    * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
    * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
    *
    * Licensed under The MIT License
    * Redistributions of files must retain the above copyright notice.
    *
    * @author        Technology Lab No.I <tech1@toancauxanh.vn>
    * @link          
    * @package       API.Controller
    * @since         Green v 1.0
    * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
    */
    App::uses('ApiAppController', 'Api.Controller');
    App::uses('str_utility','Vendor');   
    Class ApiController extends ApiAppController {

        /**
        * Use model class
        *
        * @var array
        */
        public $uses = array('Node.Node','Node.IndexNode','Node.Index','View.Contact','Node.NodeTerm','Node.Term', 
            'Node.Gallery','Node.NodeType','Node.MoveNode','Node.Question','User.User','Node.Order','Node.Item','Node.Information');          
        /**
        * Use model class
        *
        * @var array
        */
        public $helpers = array('Text', 'String','Js');
        public $compenents= array('RequestHandler');       
        public static $is_mobile = false;    
        public static $query = '';    
        public static $data = '';
        public function beforeFilter() {                          
            parent::beforeFilter();  
            self::$is_mobile = self::ismobile();
            self::$query = $this->request->query;
            self::$data = $this->request->data;
            $this->autoRender = false;
            if (in_array($this->request['action'], array('forgetPass'))) 
            {            
                $this->Components->disable('Security');
            }               
        }
        public function index(){
            
        }                     
        public function api_test(){              
            $data = array(
                1=> 'data 1',
                2=> 'data 2'
            );            
            /**
                Trường hợp biến is_mobile trả về true thì render dữ liệu kiểu json dành cho thiết bị mobile
                Ngược lại: return dữ liệu kiểu mảng cho máy tính 
            */
            if(self::$is_mobile){
                echo json_encode($data);              
            }else{return $data;}             
        }                                     
}
?>